﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.WindowsAPICodePack.Dialogs;
using QuickPasteToolWeb.Helper;
using QuickPasteToolWeb.Infrastructure;
using QuickPasteToolWeb.Model;
using QuickPasteToolWeb.Service;
using System.Windows.Forms;

namespace QuickPasteToolWeb
{
    public partial class SettingViewModel : ObservableObject
    {
        [ObservableProperty]
        private string? _folder;

        [ObservableProperty]
        private ShowType _showType;

        [ObservableProperty]
        private bool _isOpenWebSearch;


        public SettingViewModel()
        {

        }

        [RelayCommand]
        public void SelectFolder()
        {

            var dialog = new FolderBrowserDialog
            {
                Description = "Select Default Folder"
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Folder = dialog.SelectedPath;
            }
        }

        [RelayCommand]
        public void SaveSetting()
        {
            var model = new SettingModel() { Folder = _folder, ShowType = _showType ,IsOpenWebSearch = _isOpenWebSearch };
            SettingHelper.SaveSetting(model);
        }

        [RelayCommand]
        public void ResetSetting()
        {
            SettingHelper.ResetSetting();
        }
    }
}
